/***********************************************
* Filename:  		App.cpp
* Date:      		01/12/2014
* Mod. Date: 		01/12/2014
* Author:    		Night
* Purpose:   		Handles the logic for our application
************************************************/

#include "App.h"

CApp::CApp(void)
{
	m_pRenderer = nullptr;
	m_pInput = CWinM_InputHandler::GetInstance();
};

CApp::~CApp(void)
{
};

void CApp::Init( HWND _hWNd, const unsigned int _unWindowWidth, const unsigned int _unWindowHeight )
{
	if( m_pRenderer == nullptr )
	{
		IRenderer::Create( &m_pRenderer );
		m_pRenderer->Init(_hWNd, _unWindowWidth, _unWindowHeight );
	}
};

void CApp::Release( void )
{
	if( m_pRenderer != nullptr )
	{
		m_pRenderer->Release();
		delete m_pRenderer;
		m_pRenderer = nullptr;
	}
};

bool CApp::main( void )
{
	if( Input() == false )
	{
		return false;
	}

	Render();

	return true;
};

#include "render\DirectX\DXScreenRender.h"
bool CApp::Input( void )
{
	if( KEY_PRESSED( VK_ESCAPE ) )
		return false;

	if( KEY_PRESSED( VK_SPACE ) )
	{
		((CDXHandler*)(m_pRenderer))->GetScreenRender()->UpdateTexture( "PS4.png" );
	}

	return true;
};
	
void CApp::Render( void )
{
	// Update things here

	// Render the app
	{
		m_pRenderer->Clear();

		m_pRenderer->BeginScene();
		{
			m_pRenderer->Render();
		}
		m_pRenderer->EndScene();
		m_pRenderer->Present();
	}
};